﻿using System.Configuration;

namespace SimpleORM
{
    public class ProviderElement : ConfigurationElement
    {
        #region Fields

        private const string stringProviderName = "name";
        private const string stringProviderType = "type";

        #endregion

        #region Properties

        [ConfigurationProperty(stringProviderName)]
        public string Name
        {
            get { return (string)this[stringProviderName]; }
            set { this[stringProviderName] = value; }
        }

        [ConfigurationProperty(stringProviderType)]
        public string Type
        {
            get { return (string)this[stringProviderType]; }
            set { this[stringProviderType] = value; }
        }

        #endregion
    }

    public class ProviderElementCollection : ConfigurationElementCollection
    {
        #region Properties

        public ProviderElement this[int index]
        {
            get { return (ProviderElement)BaseGet(index); }
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        protected override string ElementName
        {
            get { return stringProvider; }
        }

        #endregion

        #region Fields

        private const string stringProvider = "add";

        #endregion

        #region Methods

        protected override ConfigurationElement CreateNewElement()
        {
            return new ProviderElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return (element as ProviderElement).Name;
        }

        #endregion
    }
}
